#ifndef VRPDOCUMENT_H
#define VRPDOCUMENT_H

#include <QObject>
#include <QWidget>
#include <QPointF>
#include <QList>
#include <QPair>

#include "VRPRouteGraph.h"
#include "VRPObjects.h"

class VRPDocument : public QObject
{
    Q_OBJECT
public:
    explicit VRPDocument(QObject *parent = 0);
    ~VRPDocument();

    bool isEmpty();

    void setRoutingParentWidget(QWidget* widget);

    void setDepo(const QPointF& depoPoint);
    DepoPtr getDepo();

    CustomerPtr addCustomer(const CustomerInfo& customerInfo);
    void removeCustomer(CustomerPtr customer);
    CustomerPtr customerAtPoint(CirclePointPtr point);
    int getCustomersCount() const;

    VehiclePtr addVehicle();

    QList<CustomerPtr>& customerListRef();
    QList<VehiclePtr>& vehicleListRef();

signals:
    void loaded();

public slots:
    void load();
    void save();
    void clear();

private:
    bool rouning(const CustomerInfo& customerInfo,
                 QList< QPair<CustomerPtr, RouteType> >& routeList,
                 RouteType& depoRoute);

private:
    VRPRouteGraphTraits::Graph graph_;
    VRPRouteGraphTraits::VertexNameMap nameMap_;
    VRPRouteGraphTraits::VertexBackhaulMap bhMap_;
    VRPRouteGraphTraits::VertexCoordinateMap coordMap_;
    VRPRouteGraphTraits::VertexDemandMap demandMap_;
    VRPRouteGraphTraits::EdgeWeightMap weightMap_;
    VRPRouteGraphTraits::EdgeRouteMap routeMap_;

    DepoPtr depo_;
    QList<CustomerPtr> customerList_;
    QList<VehiclePtr> vehicleList_;

    QWidget* routingParentWidget_;
};

#endif // VRPDOCUMENT_H
